﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Complaint.Models.Dtos;

namespace Complaint.Repositories
{
    public class SettlementTypeRepository : BaseRepository<SettlementType>, IRepository<SettlementType>
    {
        #region Implementation of IRepository<SettlementType>

        /// <summary>
        /// Creates the passed instance of the type to the data store.
        /// </summary>
        /// <param name="dataTransferObject">The instance of the type to create to the data store.</param>
        public void Create(SettlementType dto)
        {
            ObjectContext.AddToSettlementType(dto);
            Update(dto);
        }

        /// <summary>
        /// Retrieves all instances of the type T.
        /// </summary>
        /// <returns>The requested instances.</returns>
        public IQueryable<SettlementType> FindAll()
        {
            return ObjectContext.SettlementType;
        }

        /// <summary>
        /// Retrieves an instance of the type T by its given ID from the data store.
        /// </summary>
        /// <param name="id">The ID of the instance to retrieve.</param>
        /// <returns>The requested instance.</returns>
        public SettlementType FindById(int id)
        {
            return FindAll().FirstOrDefault(s => s.SettlementTypeID == id);
        }

        /// <summary>
        /// Retrieves an instance of the type T by its given name from the data store.
        /// </summary>
        /// <param name="name">The name of the instance to retrieve.</param>
            /// <returns>The requested instance.</returns>
        public IQueryable<SettlementType> FindByName(string name)
        {
            return FindAll().Where(s => s.Type.Contains(name));
        }

        #endregion
    }
}
